import request from '@/config/axios'
import {
  ContentRejectReqVO,
  ContentApproveReqVO,
  ContentMoveReqVO,
  ContentCopyReqVO,
  ContentMarkReqVO,
  ContentBlockReqVO,
  ContentPushReqVO,
  ContentRelateAddReqVO,
  ContentRelateSortReqVO
} from './types'

export interface ContentVO {
  id: number
  modelId: number
  siteId: number
  channelId: number
  status: number
  title: string
  releaseTime: Date
  topStatus: number
  sort: number
  originContentId: number
  createMode: number
  deptId: number
  userId: number
  editorType: number
}

export interface ContentPageReqVO extends PageParam {
  modelId?: number
  siteId?: number
  channelId?: number
  status?: number
  title?: string
  releaseTime?: Date[]
  topStatus?: number
  sort?: number
  originContentId?: number
  createMode?: number
  deptId?: number
  userId?: number
  createTime?: Date[]
}

export interface ContentExcelReqVO {
  modelId?: number
  siteId?: number
  channelId?: number
  status?: number
  title?: string
  releaseTime?: Date[]
  topStatus?: number
  sort?: number
  originContentId?: number
  createMode?: number
  deptId?: number
  userId?: number
  createTime?: Date[]
}

export interface ContentRelateReqVO extends PageParam {
  contentId?: number
}
export interface ContentIndexPageReqVO extends PageParam {
  siteId?: number
  channelId?: number
  title?: string
}

export interface ContentIndexResetReqVO extends PageParam {
  siteId?: number
  channelId?: number | undefined
}
export interface SensitiveWordCheckVO {
  text: string
}
export interface ContentVersionReqVO extends PageParam {
  contentId?: number
}

export const convertDocApi = `${import.meta.env.VITE_BASE_API}/cms/content/convertDoc`
export const convertLibraryApi = `${import.meta.env.VITE_BASE_API}/cms/content/convertLibrary`

//查询是否开启转换服务
export const getConvertEnabledApi = async () => {
  return await request.get({ url: '/cms/content/getConvertEnabled' })
}
//查询是否开启发布内容引用多栏目功能
export const getPublishMultiChannelEnabledApi = async () => {
  return await request.get({ url: '/cms/content/getPublishMultiChannelEnabled' })
}
// 查询内容列表
export const getContentPageApi = async (params: ContentPageReqVO) => {
  return await request.get({ url: '/cms/content/page', params })
}

// 查询待审核内容列表
export const getTodoContentPageApi = async (params: PageParam) => {
  return await request.get({ url: '/cms/content/todopage', params })
}
// 查询内容详情
export const getContentApi = async (id: number) => {
  return await request.get({ url: '/cms/content/get?id=' + id })
}

// 新增内容
export const createContentApi = async (data: ContentVO) => {
  //默认创建内容发布状态
  return await request.post({ url: '/cms/content/create', data })
}
// 新增实时预览内容
export const createPreviewContentApi = async (data: ContentVO) => {
  return await request.post({ url: '/cms/content/createPreview', data })
}
// 修改内容
export const updateContentApi = async (data: ContentVO) => {
  return await request.post({ url: '/cms/content/update', data })
}
// 修改内容并提交审核
export const updateContentAndSubmitApi = async (data: ContentVO) => {
  return await request.post({ url: '/cms/content/updateAndSubmit', data })
}
// 创建内容并提交审核
export const createContentAndSubmitApi = async (data: ContentVO) => {
  return await request.post({ url: '/cms/content/createAndSubmit', data })
}
// 删除内容
export const deleteContentApi = async (ids: number[]) => {
  return await request.post({ url: '/cms/content/delete', data: ids })
}

//提交工作流审核
export const submitContentApi = async (id: number) => {
  return await request.post({ url: '/cms/content/submit', data: { id: id } })
}
//归档
export const archiveContentApi = async (ids: number[]) => {
  return await request.post({ url: '/cms/content/archive', data: ids })
}
//置顶
export const topContentApi = async (ids: number[], topLevel: number) => {
  return await request.post({ url: '/cms/content/top', data: { ids, topLevel } })
}
//移动
export const moveContentApi = async (data: ContentMoveReqVO) => {
  return await request.post({ url: '/cms/content/move', data: data })
}
//复制
export const copyContentApi = async (data: ContentCopyReqVO) => {
  return await request.post({ url: '/cms/content/copy', data: data })
}
//推送
export const pushContentApi = async (data: ContentPushReqVO) => {
  return await request.post({ url: '/cms/content/push', data: data })
}
//标记
export const markContentApi = async (data: ContentMarkReqVO) => {
  return await request.post({ url: '/cms/content/mark', data: data })
}
//设置区块
export const blockContentApi = async (data: ContentBlockReqVO) => {
  return await request.post({ url: '/cms/content/block', data: data })
}
//下线
export const offlineContentApi = async (ids: number[]) => {
  return await request.post({ url: '/cms/content/offline', data: ids })
}
//发布
export const publishContentApi = async (ids: number[]) => {
  return await request.post({ url: '/cms/content/publish', data: ids })
}
//彻底删除
export const twoDeleteContentApi = async (ids: number[]) => {
  return await request.post({ url: '/cms/content/twoDelete', data: ids })
}
// 查询相关内容列表
export const getContentRelatePageApi = async (params: ContentRelateReqVO) => {
  return await request.get({ url: '/cms/content/relate/page', params })
}
//删除相关内容
export const deleteContentRelateApi = async (id: number) => {
  return await request.post({ url: '/cms/content/relate/delete?id=' + id })
}
//添加相关内容
export const addContentRelateApi = async (data: ContentRelateAddReqVO) => {
  return await request.post({ url: '/cms/content/relate/create', data: data })
}
//排序相关内容
export const sortContentRelateApi = async (data: ContentRelateSortReqVO) => {
  return await request.post({ url: '/cms/content/relate/sort', data: data })
}
//审核通过
export const approveContentApi = async (data: ContentApproveReqVO) => {
  return await request.post({ url: '/cms/content/approve', data: data })
}
//审核不通过
export const rejectContentApi = async (data: ContentRejectReqVO) => {
  return await request.post({ url: '/cms/content/reject', data: data })
}
// 查询内容索引列表
export const getContentIndexPageApi = async (params: ContentIndexPageReqVO) => {
  return await request.get({ url: '/cms/content/index/page', params })
}
//重置内容索引
export const resetContentIndexApi = async (data: ContentIndexResetReqVO) => {
  return await request.post({ url: '/cms/content/index/reset', data: data })
}
// 导出内容 Excel
export const exportContentApi = async (params: ContentExcelReqVO) => {
  return await request.download({ url: '/cms/content/export-excel', params })
}
//检查是否存在敏感词
export const checkSensitiveWordApi = async (data: SensitiveWordCheckVO) => {
  return await request.post({ url: '/cms/content/checkSensitiveWord', data: data })
}
//查询内容待审核内容数量
export const getToAuditContentApi = async () => {
  return await request.get({ url: '/cms/content/toauditContentCount' })
}
// 查询内容版本列表
export const getContentVersionPageApi = async (params: ContentVersionReqVO) => {
  return await request.get({ url: '/cms/content-version/page', params })
}
//删除内容版本内容
export const deleteContentVersionApi = async (id: number) => {
  return await request.post({ url: '/cms/content-version/delete?id=' + id })
}
//保存当前内容版本
export const createContentVersionApi = async (id: number) => {
  return await request.post({ url: '/cms/content-version/create?id=' + id })
}
//恢复内容版本
export const restoreContentVersionApi = async (id: number) => {
  return await request.post({ url: '/cms/content/restoreText?id=' + id })
}
//查询内容版本数据
export const getContentVersionApi = async (id: number) => {
  return await request.get({ url: '/cms/content-version/get?id=' + id })
}
// 查询统计用户绩效列表
export const getUserScoreStatPage = async (params) => {
  return await request.get({ url: '/cms/content/statistic/score-stat/by-user', params })
}
// 查询统计组织绩效列表
export const getDeptScoreStatPage = async (params) => {
  return await request.get({ url: '/cms/content/statistic/score-stat/by-dept', params })
}
// 查询内容访问量列表
export const getContentTopViewPageApi = async (params: ContentPageReqVO) => {
  return await request.get({ url: '/cms/content/getContentViewPage', params })
}
